package io.adrainty.bolee.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.security.models.entity.PostEntity;
import io.adrainty.bolee.security.service.IPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/12 上午12:20
 */

@Tag(name = "职位管理接口")
@RestController
@RequestMapping("/post")
public class PostController {

    @Resource
    private IPostService postService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "分页获取岗位")
    public ResultDTO<IPage<PostEntity>> findPostPage(@RequestBody PostEntity entity,
                                                     @PathVariable("pageNum") Integer pageNum,
                                                     @PathVariable("pageSize") Integer pageSize) {
        IPage<PostEntity> pageResult = postService.findPostPage(entity, pageNum, pageSize);
        return ResultDTOUtil.success(pageResult);
    }

    @PutMapping
    @Operation(summary = "岗位添加")
    public ResultDTO<PostEntity> createPost(@RequestBody PostEntity entity) {
        PostEntity result = postService.createPost(entity);
        return ResultDTOUtil.success(result);
    }

    @PatchMapping
    @Operation(summary = "岗位修改")
    public ResultDTO<Boolean> updatePost(@RequestBody PostEntity entity) {
        Boolean result = postService.updatePost(entity);
        return ResultDTOUtil.success(result);
    }

    @PostMapping("/list")
    @Operation(summary = "岗位列表")
    public ResultDTO<List<PostEntity>> listPost(@RequestBody PostEntity entity) {
        List<PostEntity> result = postService.listPost(entity);
        return ResultDTOUtil.success(result);
    }
}
